Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link config validation using pydantic #3339

Merged
merged 4 commits into from
Dec 6, 2024
Merged

Add link config validation using pydantic #3339

merged 4 commits into from
Dec 6, 2024

Conversation

therazix
Copy link
Collaborator

@therazix therazix commented Nov 2, 2024

This PR extracts the Config class from tmt.utils into its own file and also introduces config validation using Pydantic models. Currently, validation is applied only to the link configuration.

Resolves #84.

Pull Request Checklist

  • implement the feature
  • extend the test coverage

@martinhoyer
Copy link
Collaborator

Nice!
The '<2' limit for pydantic version won't work as Fedora only have v2.
Do you know why epel9 was never updated to v2?

What do you think about this settings for BaseModel?
https://docs.astral.sh/ruff/settings/#lint_flake8-type-checking_runtime-evaluated-base-classes

@therazix
Copy link
Collaborator Author

therazix commented Nov 5, 2024

I updated Pydantic to v2, but I'm not sure how to make it work on EPEL 9, which only supports v1.

Since Pydantic v2 supports backward compatibility with v1 through pydantic.v1, I downgraded to v1 and added Pydantic to tmt._compat. I'm not sure if this is the best solution, but it should work with both versions and ensure that we only use features from v1.

What do you think about this settings for BaseModel?
https://docs.astral.sh/ruff/settings/#lint_flake8-type-checking_runtime-evaluated-base-classes

It may be a good idea to add that. I didn't encounter any problems without it, but it may be needed in some scenarios. Added in 9481860

@therazix therazix force-pushed the fvagner-config branch 2 times, most recently from 58905c0 to 9481860 Compare November 5, 2024 17:31
tmt/config/models/__init__.py Outdated Show resolved Hide resolved
@therazix therazix requested a review from happz November 7, 2024 15:12
@therazix therazix force-pushed the fvagner-config branch 2 times, most recently from b3be792 to e7ef3ff Compare November 21, 2024 11:28
@psss
Copy link
Collaborator

psss commented Nov 21, 2024

As this is a new approach, it would be good to get a few more reviews. Moving to 1.40.

@psss psss modified the milestones: 1.39, 1.40 Nov 21, 2024
@psss psss added area | config User configuration priority | must high priority, must be included in the next release labels Nov 21, 2024
Copy link
Collaborator

@skycastlelily skycastlelily left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM:)

@skycastlelily
Copy link
Collaborator

I followed the extended test ,and put the following ~/.config/link.fmf:

issue-tracker:
  - type: jira
    url: https://issues.redhat.com
    tmt-web-url: http://tmt.testing-farm.io/
    unkown: value

Then run tmt link command, got no warning, I guess we could warn users by printing the str(error.cause),
similar as how your test works? @therazix

@therazix
Copy link
Collaborator Author

I followed the extended test ,and put the following ~/.config/link.fmf:

issue-tracker:
  - type: jira
    url: https://issues.redhat.com
    tmt-web-url: http://tmt.testing-farm.io/
    unkown: value

Then run tmt link command, got no warning, I guess we could warn users by printing the str(error.cause), similar as how your test works? @therazix

You are right, thanks for the review. The issue was that SpecificationError was caught by except tmt.utils.MetadataError, so no exception was raised. It should be fixed in 0b7cd2b.

@skycastlelily
Copy link
Collaborator

It should be fixed in 0b7cd2b.

Confirmed.

@seberm seberm self-requested a review December 4, 2024 14:23
@happz happz added status | ready for merge The only missing piece is to do the rebase the current 'main' and let the CI finish. ci | full test Pull request is ready for the full test execution labels Dec 5, 2024
Copy link
Collaborator

@psss psss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! The error messages which pydantic generates for invalid data look very useful. Thanks for implementing this!

@psss
Copy link
Collaborator

psss commented Dec 6, 2024

Rawhide failure irrelevant, merging.

@psss psss merged commit 70048a6 into main Dec 6, 2024
19 of 20 checks passed
@psss psss deleted the fvagner-config branch December 6, 2024 10:44
@psss psss changed the title Add link config validation Add link config validation using pydantic Dec 6, 2024
@psss psss self-assigned this Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area | config User configuration ci | full test Pull request is ready for the full test execution priority | must high priority, must be included in the next release status | ready for merge The only missing piece is to do the rebase the current 'main' and let the CI finish.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a user configuration
6 participants